<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #con {
            height: 200px;
            width: 200px;
        }
        .boxborder {
            border: 3px solid black;
        }
    </style>
    <!-- <script>
        window.onload = function(){
            document.getElementById('con').style.background = 'red';
        }
    </script> -->
</head>
<body>
    <div id="con">

    </div>
</body>
<!-- 习惯将js脚本放在body标签之后，js执行会阻塞后面代码的解释执行 -->
<script>
    window.onload = function(){
        // let conObj = document.querySelector("#con"); //选中#con集合中第一个元素
        let conObj = document.querySelectorAll("#con")[0];
        conObj.style.background = 'red';
        conObj.classList.add('boxborder')
    }
</script>
<script src="" async></script>
</html>